﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using YSC_App_WebApi.RestClient;
using YSC_Services.BLL.Services_Web.Interfaces;

namespace YSC_App_WebApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class BasisController : ControllerBase
    {
        private IBasisAppServices _pro;

        public BasisController(IBasisAppServices pro)
        {
            this._pro = pro;
        }

        /// <summary>
        /// 地区列表
        /// </summary>
        /// <param name="level">等级</param>
        /// <param name="code">编码</param>
        /// <param name="name">地区名称</param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetAreaAll")]

        public ActionResult GetAreaAll(int level = 0, string code = null, string name = null)
        {
            var ret = _pro.GetAreaAll(level, code, name);
            return Ok(ret);
        }

        /// <summary>
        /// 基础数据
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetDictionaryAll")]
        public ActionResult GetDictionaryAll(string type)
        {
            var ret = _pro.GetDictionaryAll(type);
            return Ok(ret);
        }

        /// <summary>
        /// 市场列表
        /// </summary>
        /// <param name="userId">用户id</param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetMarketUnitAll")]
        [TestAuthorize("User_Edit")]
        public ActionResult GetMarketUnitAll()
        {
            var claimsAll = HttpContext.User.Claims.Select(p => new { p.Type, p.Value });
            var items = claimsAll.FirstOrDefault(p => p.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier");

            var userid = string.Empty;

            if (items != null)
                userid = items.Value;

            var ret = _pro.GetMarketUnitAll(userid);
            return Ok(ret);
        }

        /// <summary>
        /// 鱼种信息
        /// </summary>
        /// <param name="fishType">鱼种类型</param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetFingerlingTypeAll")]
        public ActionResult GetFingerlingTypeAll(string fishType)
        {
            var ret = _pro.GetFingerlingTypeAll(fishType);
            return Ok(ret);
        }

        /// <summary>
        /// 鱼种规格
        /// </summary>
        /// <param name="fishName">鱼种名称</param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetDesciptionAll")]
        public ActionResult GetDesciptionAll(string fishName)
        {
            var ret = _pro.GetDesciptionAll(fishName);
            return Ok(ret);
        }
    }
}